package com.sqx.modules.navigation.controller.app;

import com.sqx.common.utils.Result;
import com.sqx.common.validator.ValidatorUtils;
import com.sqx.common.validator.group.AddGroup;
import com.sqx.common.validator.group.UpdateGroup;
import com.sqx.modules.navigation.entity.JgDh;
import com.sqx.modules.navigation.service.JgDhService;
import com.sqx.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RestController
@Api(value = "金刚-导航", tags = {"金刚-导航"})
@RequestMapping("/app/jg/dh")
public class AppJgDhController extends AbstractController {
    @Autowired
    private JgDhService jgDhService;

//    @GetMapping("/selectJgDhList")
    @ApiOperation("金刚-导航列表")
    @RequestMapping(value = "/selectJgDhList", method = RequestMethod.GET)
    public Result selectJgDhList(Integer page, Integer limit, Integer userType, Integer type){
        return Result.success().put("data",jgDhService.queryAppPage(page, limit, userType, type));
    }

    /**
     * 金刚-导航详情
     */
//    @GetMapping("/info/{id}")
    @ApiOperation("金刚-导航详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public Result info(@PathVariable("id") Long id){
        JgDh jgdh = jgDhService.getById(id);
        return Result.success().put("jgdh", jgdh);
    }

    /**
     * 保存金刚-导航
     */
//    @PostMapping("/save")
    @ApiOperation("保存")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody JgDh jgdh){
        ValidatorUtils.validateEntity(jgdh, AddGroup.class);

        jgDhService.save(jgdh);

        return Result.success();
    }

    /**
     * 修改金刚-导航
     */
//    @PostMapping("/update")
    @ApiOperation("修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result update(@RequestBody JgDh jgdh){
        ValidatorUtils.validateEntity(jgdh, UpdateGroup.class);

        jgDhService.updateById(jgdh);

        return Result.success();
    }

    /**
     * 删除金刚-导航
     */
//    @PostMapping("/delete")
    @ApiOperation("删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Result delete(@RequestBody Long[] ids){
        jgDhService.removeByIds(Arrays.asList(ids));
        return Result.success();
    }
}
